package com.xique.park.controller.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xique.common.core.domain.R;
import com.xique.park.bean.domain.ParkDeviceNew;
import com.xique.park.service.service.IParkDeviceNewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 远程视频
 *
 * @author guolingling
 */
@RestController
@RequestMapping("/web/ParkDeviceNew")
public class WebParkDeviceNewController {

    @Autowired
    IParkDeviceNewService parkDeviceNewService;

    @GetMapping("/deviceList")
    public R<List<ParkDeviceNew>> getParkDeviceNew(HttpServletRequest request) {
        String parkIds = request.getHeader("projectId");
        List<ParkDeviceNew> list;
        if (parkIds != null) {
            list = new ArrayList<>(getDeviceNew(Long.valueOf(parkIds)));
        } else {
            return R.fail("参数为空");
        }
        return R.ok(list);
    }

    public List<ParkDeviceNew> getDeviceNew(Long parkId) {
        QueryWrapper<ParkDeviceNew> wrapper = new QueryWrapper<>();
        if (parkId != null) {
            wrapper.eq("park_id", parkId);
        }
        wrapper.eq("record_status", "normal");
        wrapper.eq("status", "normal");
        return parkDeviceNewService.list(wrapper);
    }

}
